<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>17-点谁谁变红</title>
  <style>
    .active {
      background-color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>vue的例子</h1>
    <p>{{msg}}</p>
    <button v-for="(item,index) in list" :class="{active: currentIndex==index }"
      @click="btnClick(index)">{{item}}</button>
  </div>
  <script src="../js/vue.js"></script>
  <script>
    Vue.config.productionTip = false; // 关闭生产提示
    const vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello',
        list: ['苹果', '香蕉', '桔子', '菠萝', '西瓜', '葡萄', '榴莲'],
        currentIndex: ''
      },
      methods: {
        btnClick(index) {
          // 当我们单击了某个按钮的时候，可以将当前按钮的索引传过来
          this.currentIndex = index
        }
      }
    })
  </script>
</body>
</html>